package com.xlf.service.base.controller.client;

import com.xlf.common.core.annotation.Anonymous;
import com.xlf.common.core.pojo.mode.AjaxResult;
import com.xlf.common.core.pojo.mode.BaseController;
import com.xlf.pojo.dto.ContestListReqDTO;
import com.xlf.service.base.pojo.dto.RegisterContestDTO;
import com.xlf.service.base.service.ContestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author xlf 2734029211@qq.com
 * @Date 2023/12/16 16:09
 * @Description: TODO 竞赛模块
 * @Version 1.0
 */
@RestController
@RequestMapping("/base/contest")
public class ContestController extends BaseController {

    @Autowired
    ContestService contestService;


    /***
     * 获取比赛列表
     * @param contestListVO
     * @return
     */
    @Anonymous
    @PostMapping("/list")
    public AjaxResult list(@RequestBody ContestListReqDTO contestListVO){
        return success(contestService.getContestListVO(contestListVO));
    }


    /***
     * 获取最近开始的比赛列表
     * @return
     */
    @Anonymous
    @GetMapping("/getRecentlyContest")
    public AjaxResult recentlyContest(){
        return success(contestService.getRecentlyContest());
    }


    /**
     * 获取比赛详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public AjaxResult query(@PathVariable(value = "id") Long id){
        return success(contestService.getContestVO(id));
    }

    /**
     * 报名
     * @param registerContestDTO
     * @return
     */
    @PostMapping("/register")
    public AjaxResult register(@RequestBody  RegisterContestDTO registerContestDTO){
        contestService.register(registerContestDTO);
        return success();
    }

    /**
     * 获取比赛题目
     * @param cid
     * @return
     */
    @GetMapping("/getProblemList/{cid}")
    public AjaxResult getContestProblemVO(@PathVariable(value = "cid") Long cid){
        return success(contestService.getContestProblemVO(cid));
    }


    /**
     * 比赛页面获取比赛消息
     * @param cid
     * @return
     */
    @GetMapping("/info/{cid}")
    public AjaxResult getContestInfo(@PathVariable(value = "cid") Long cid){
        return success(contestService.getContestInfo(cid));
    }

    /**
     * 获取比赛题目参照
     * @param id
     * @return
     */
    @GetMapping("/getProblemList/ref/{id}")
    public AjaxResult getContestProblemReVO(@PathVariable(value = "id") Long id){
        return success(contestService.getContestProblemReVO(id));
    }

    /**
     *  获取比赛题目详情
     * @param pid
     * @return
     */
    @GetMapping("/getProblemVO/{pid}")
    public AjaxResult getProblemVO(@PathVariable(value = "pid") Long pid){
        return success(contestService.getContestProblemDetailVO(pid));
    }



    /**
     * 从缓存中获取比赛实时排行榜
     * @param cid
     * @return
     */
    @Deprecated
    @GetMapping("/getContestRank/r/{cid}")
    public AjaxResult getContestRank(@PathVariable(value = "cid") Long cid){
        return success(contestService.getContestByRedisRank(cid));
    }

    /**
     * 从mysql中获取比赛实时排行榜
     * @param cid
     * @return
     */
    @GetMapping("/getContestRank/s/{cid}")
    public AjaxResult getContestByMysqlRank(@PathVariable(value = "cid") Long cid){
        return success(contestService.getContestByMysqlRank(cid));
    }


}
